import { BaseWindow } from "../../../../component/window/BaseWindow";
import { ILayer } from "../../../../mvc/interfaces/ILayer";
import { Language } from "../../../../../extend/language/Language";
import { ShopConfig } from "../../../resource/ShopConfig";
import { ECategory } from "../../../../../Message/Public/ECategory";
import { EProp } from "../../../../../Message/Public/EProp";
import { ObjCreate } from "../../common/ObjCreate";
import { GImageBitmap } from "../../../../../com/mui/controls/GImageBitmap";
import { ImagesConst } from "../../../resource/ImagesConst";
import { PetItem } from "../PetItem";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { TilePanel } from "../../equipment/TilePanel";
import { PetBwTypeRenderer } from "./PetBwTypeRenderer";
import { BuyCommonPanel } from "../skill/BuyCommonPanel";
import { PublicMessageConfig } from "../../../resource/PublicMessageConfig";
import { SPetInfo } from "../../../../../Message/Game/SPetInfo";
import { PetUtil } from "../info/PetUtil";
import { CareerConfig } from "../../../resource/CareerConfig";
import { GameDefConfig } from "../../../resource/GameDefConfig";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { MsgManager } from "../../../manager/MsgManager";
import { ItemsUtil } from "../../shortcuts/item/ItemsUtil";
import { Alert } from "../../../../../com/mui/controls/Alert";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { PetColor } from "../info/PetColor";
import { PetType } from "../info/PetType";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { ShopItemInfo } from "../../../resource/info/ShopItemInfo";
import { ItemData } from "../../../resource/info/ItemData";
import { _careerCode } from "../../../../../this/_careerCode";
type int = number;
//class PetBrainwashWindow
    
    export  class PetBrainwashWindow extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this.setSize(500, 370);
            this.titleHeight = 30;
            this.title = Language.getString(54039);
            return;
        }

        protected /* override */ createChildren(): void
        {
            var loc1=null;
            super.createChildren();
            this._bwProp = ShopConfig.instance.getItemByType(ECategory._ECategoryProp, EProp._EPropPetXisui);
            ObjCreate.createBg(17, 44, 285, 270, this);
            ObjCreate.createBg(305, 44, 175, 310, this);
            this.addChild(new GImageBitmap(ImagesConst.PetNameBg, 20, 50));
            this._petItem = new PetItem();
            this._petItem.isDragAble = false;
            this._petItem.isDropAble = false;
            this._petItem.setSize(48, 48);
            this._petItem.move(43, 55);
            this.addChild(this._petItem);
            this._nameTxt = ObjCreate.createTextField("", 115, 78, 110, 25, this, new GTextFormat(FontUtil.songtiName, 14, 11661311));
            this._nameTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            ObjCreate.createBg(25, 120, 260, 2, this, ImagesConst.SplitLine);
            ObjCreate.createTextField(Language.getString(54040), 25, 130, 110, 20, this, GlobalStyle.textFormat2);
            var loc2=0;
            while (loc2 < 3) 
            {
                loc1 = ObjCreate.createBg(40, 150, 68, 68, this, ImagesConst.PackItemBg);
                loc1.x = 40 + loc2 * 86;
                ++loc2;
            }
            this._typeList = new TilePanel();
            this._typeList.setStyle("cellRenderer", PetBwTypeRenderer);
            this._typeList.horizontalGap = 18;
            this._typeList.columnWidth = 68;
            this._typeList.rowHeight = 68;
            this._typeList.setSize(240, 68);
            this._typeList.move(41, 151);
            this.addChild(this._typeList);
            ObjCreate.createBg(25, 230, 260, 2, this, ImagesConst.SplitLine);
            ObjCreate.createTextField(Language.getString(54041), 25, 240, 160, 20, this, GlobalStyle.textFormat2);
            this._buyPanel = new BuyCommonPanel();
            this._buyPanel.isShowBg = false;
            this._buyPanel.updateByShopItemInfo(this._bwProp);
            this._buyPanel.x = 25;
            this._buyPanel.y = 250;
            this.addChild(this._buyPanel);
            this._bwBtn = ObjCreate.createGButton(Language.getString(54042), 140, 330, 60, 24, this);
            this._bwBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBwBtnClickHandler);
            this._descTxt = ObjCreate.createTextField("", 310, 49, 170, 305, this);
            this._descTxt.wordWrap = true;
            this._descTxt.multiline = true;
            this._descTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._descTxt.htmlText = "<textFormat leading=\'5\'>" + PublicMessageConfig.instance.getPetForgeTextByName("xisuiDesc") + "</textFormat>";
            return;
        }

        public updatePet(arg1: SPetInfo): void
        {
            var loc1=null;
            this._petInfo = arg1;
            if (arg1) 
            {
                this._nameTxt.htmlText = PetUtil.getPetName(arg1);
                this._petItem.dragSource = arg1;
                loc1 = CareerConfig.instance.getInfoByCode(arg1.career);
                this._careerCode = loc1.code;
                this._typeArray = [{"type": _careerCode, "value": GameDefConfig.instance.getPetType(this._petInfo.reinLevel, 1)}, {"type": _careerCode, "value": GameDefConfig.instance.getPetType(this._petInfo.reinLevel, 2)}, {"type": _careerCode, "value": GameDefConfig.instance.getPetType(this._petInfo.reinLevel, 3)}];
                this._typeList.dataProvider = new DataProvider(this._typeArray);
            }
            this._typeList.selectedIndex = -1;
            this._typeList.drawNow();
            return;
        }

        /* internal  */onBwBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var e: Object /* flash.events.MouseEvent */;
            var packAmount: int;
            var packItemArray: Array<any>;
            var selectType: int;
            var onBtnClickHandler: Function;

            var loc1;
            packAmount = 0;
            packItemArray = null;
            selectType = 0;
            e = arg1;
            if (this._petInfo) 
            {
                packAmount = this._buyPanel.packItemAmount;
                packItemArray = this._buyPanel.itemDataArray;
                if (packAmount == 0) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(54043) + ItemsUtil.getItemName(this._buyPanel.itemData));
                    return;
                }
                this._propItemData = this._buyPanel.getToUseItemData();
                if (this._propItemData) 
                {
                    onBtnClickHandler = (arg1: int): void
                    {
                        if (arg1 == Alert.OK) 
                        {
                            Dispatcher.dispatchEvent(new DataEvent(EventName.PetXisui, {"uid": _petInfo.uid, "type": selectType}));
                            Alert.resetToDefault();
                        }
                        return;
                    }
                    if (this._typeList.selectedItem == null) 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(54044));
                        return;
                    }
                    selectType = this._typeList.selectedItem["value"] as int;
                    if (selectType == this._careerCode) 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(54044));
                        this._typeList.selectedIndex = -1;
                        return;
                    }
                    Alert.show(Language.getStringByParam(54045, PetUtil.getPetName(this._petInfo), PetColor.getColorName(this._petInfo), PetType.getTypeName(selectType)), null, Alert.OK | Alert.CANCEL, null, onBtnClickHandler);
                }
            }
            return;
        }

        /* internal */ /* var */_petItem: PetItem;

        /* internal */ /* var */_nameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_typeList: TilePanel;

        /* internal */ /* var */_buyPanel: BuyCommonPanel;

        /* internal */ /* var */_bwBtn: GButton;

        /* internal */ /* var */_descTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_bwProp: ShopItemInfo;

        /* internal */ /* var */_propItemData: ItemData;

        /* internal */ /* var */_petInfo: SPetInfo;

        /* internal */ /* var */_typeArray: Array<any>;

        /* internal */ /* var */_careerCode: int;
    }
